package com.hghivln.controller.system;

import com.hghivln.aspectj.annotation.Log;
import com.hghivln.aspectj.enums.BusinessType;
import com.hghivln.pojo.dto.RegisteredItemDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.RegisteredItemService;
import com.hghivln.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

@RestController
@RequestMapping("system/registeredItem")
public class RegisteredItemController {

    @Autowired
    private RegisteredItemService registeredItemService;

    /**
     * 分页查询
     */
    @GetMapping("listRegisteredItemForPage")
    public AjaxResult listRegisteredItemForPage(RegisteredItemDto registeredItemDto) {
        return registeredItemService.listRegisteredItemForPage(registeredItemDto);
    }


    /**
     * 添加
     */
    @PostMapping("addRegisteredItem")
    @Log(title = "添加挂号项目",businessType = BusinessType.INSERT)
    public AjaxResult addRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
        registeredItemDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return registeredItemService.addRegisteredItem(registeredItemDto);
    }

    /**
     * 修改
     */
    @PutMapping("updateRegisteredItem")
    @Log(title = "修改挂号项目",businessType = BusinessType.UPDATE)
    public AjaxResult updateRegisteredItem(@Validated RegisteredItemDto registeredItemDto) {
        registeredItemDto.setSimpleUser(ShiroUtils.getCurrentSimpleUser());
        return registeredItemService.updateRegisteredItem(registeredItemDto);
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteRegisteredItemByIds/{ids}")
    @Log(title = "删除挂号项目",businessType = BusinessType.DELETE)
    public AjaxResult deleteRegisteredItemByIds(@PathVariable @Validated @NotEmpty(message = "要删除的挂号项目ID不能为空")Long[] ids) {
        return registeredItemService.deleteRegisteredItemByIds(ids);
    }

    /**
     * 根据ID查询一个挂号项目信息
     */
    @GetMapping("getRegisteredItemById/{id}")
    public AjaxResult getRegisteredItemById(@PathVariable @Validated @NotEmpty(message = "挂号项目ID不能为空") Long id) {
        return registeredItemService.selectRegisteredItemById(id);
    }

    /**
     * 查询所有有效的检查项目信息
     */
    @GetMapping("selectAllRegisteredItem")
    public AjaxResult selectAllRegisteredItem(){
        return registeredItemService.selectAllRegisteredItem();
    }
}
